package com.ruoyi.dlxx.controller;

import java.util.List;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.dlxx.domain.DataVehicleWarning;
import com.ruoyi.dlxx.service.IDataVehicleWarningService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 数据仓库——车辆预警数据信息Controller
 *
 * @author llin
 * @date 2023-02-22
 */
@Controller
@RequestMapping("/llin/warning")
public class DataVehicleWarningController extends BaseController {

    private String prefix = "llin/warning";

    @Autowired
    private IDataVehicleWarningService dataVehicleWarningService;

    @RequiresPermissions("llin:warning:view")
    @GetMapping()
    public String warning() {
        return prefix + "/warning";
    }

    /**
     * 查询数据仓库——车辆预警数据信息列表
     */
    @RequiresPermissions("llin:warning:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DataVehicleWarning dataVehicleWarning) {
        startPage();
        List<DataVehicleWarning> list = dataVehicleWarningService.selectDataVehicleWarningList(dataVehicleWarning);
        return getDataTable(list);
    }

    /**
     * 导出数据仓库——车辆预警数据信息列表
     */
    @RequiresPermissions("llin:warning:export")
    @Log(title = "数据仓库——车辆预警数据信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DataVehicleWarning dataVehicleWarning) {
        List<DataVehicleWarning> list = dataVehicleWarningService.selectDataVehicleWarningList(dataVehicleWarning);
        ExcelUtil<DataVehicleWarning> util = new ExcelUtil<DataVehicleWarning>(DataVehicleWarning.class);
        return util.exportExcel(list, "数据仓库——车辆预警数据信息数据");
    }

    /**
     * 新增数据仓库——车辆预警数据信息
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存数据仓库——车辆预警数据信息
     */
    @RequiresPermissions("llin:warning:add")
    @Log(title = "数据仓库——车辆预警数据信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DataVehicleWarning dataVehicleWarning){
        dataVehicleWarning.setCreateBy(getLoginName());
        return toAjax(dataVehicleWarningService.insertDataVehicleWarning(dataVehicleWarning));
    }

    /**
     * 修改数据仓库——车辆预警数据信息
     */
    @GetMapping("/edit/{vehicleWarningId}")
    public String edit(@PathVariable("vehicleWarningId") String vehicleWarningId, ModelMap mmap) {
        DataVehicleWarning dataVehicleWarning = dataVehicleWarningService.selectDataVehicleWarningByVehicleWarningId(vehicleWarningId);
        mmap.put("dataVehicleWarning", dataVehicleWarning);
        return prefix + "/edit";
    }

    /**
     * 修改保存数据仓库——车辆预警数据信息
     */
    @RequiresPermissions("llin:warning:edit")
    @Log(title = "数据仓库——车辆预警数据信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DataVehicleWarning dataVehicleWarning) {
        dataVehicleWarning.setUpdateBy(getLoginName());
        return toAjax(dataVehicleWarningService.updateDataVehicleWarning(dataVehicleWarning));
    }

    /**
     * 删除数据仓库——车辆预警数据信息
     */
    @RequiresPermissions("llin:warning:remove")
    @Log(title = "数据仓库——车辆预警数据信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(dataVehicleWarningService.deleteDataVehicleWarningByVehicleWarningIds(ids));
    }
}
